<?php 

set_time_limit(0);

$re=new isRead();

echo '<pre>';

	var_dump("更新：".$re->getByrgc());

echo '</pre>';


class isRead
{

	public function getDataDb()
	{

		$json=file_get_contents('yidu.json');

		$arr=json_decode($json,true)['data'];
		$str='';

		foreach ($arr as $key => $value) {
			$str.=$value['callId']."','";
		}

		//echo strlen($str)-4;

		$str="('".substr($str,0,(strlen($str)-2)).")";

		return $str;
	}

	public function updataDb($id){


		$qure="UPDATE by_data SET isRead=1 WHERE callInstanceId in {$id};";

		//echo $qure;

		$host='localhost';
		$user='root';
		$password='root';
		$database='weizandata';
		$link=mysqli_connect($host, $user, $password, $database);
		$link->query("set names utf8");
		$result=mysqli_query($link, $qure);
		//$arr=mysqli_fetch_all($result, 1);

		//echo mysqli_error($link);

		return $result;

	}

	public function posturl($url,$data){

        $data  = json_encode($data);
        $headerArray = array("Content-Type: application/json");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $put = curl_exec($curl);

        curl_close($curl);

        return $put;
	}

	public function php_do_Url_GET($url,$params,$headers = null){ //Get get


		$url = "{$url}?" . http_build_query ($params);
		$ch = curl_init ();
		curl_setopt ( $ch, CURLOPT_URL, $url );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
		curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
		curl_setopt ( $ch, CURLOPT_POSTFIELDS, $params );
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSLVERSION, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);	

		$json_string = curl_exec ( $ch );

		$data = json_decode($json_string, true);

		curl_close ( $ch );

		return $data;
	}


	public function getFiled($variable){

		$vali='';

		foreach ($variable as $key => $value) {
		
			$filed='';

			$val='';

			foreach ($variable[$key] as $key1 => $value1) {

				if(is_array($value1)){

					$value1=json_encode($value1,JSON_UNESCAPED_UNICODE);

					$value1=addslashes($value1);

				}



				$filed.=$key1.",";

				$val.="'".$value1."',";



			}

			$filed="(".substr($filed, 0,strlen($filed)-1).")";

			$vali.="(".substr($val, 0,strlen($val)-1)."),";	

	

		}


		return ['file'=>$filed,'val'=>substr($vali,0,strlen($vali)-1)];
	}

	public function insertDb($qure){


		//$qure="UPDATE by_data SET isRead=1 WHERE callInstanceId in {$id};";

		//echo $qure;

		$host='localhost';
		$user='root';
		$password='root';
		$database='weizandata';
		$link=mysqli_connect($host, $user, $password, $database);
		$link->query("set names utf8");
		$result=mysqli_query($link, $qure);
		//$arr=mysqli_fetch_all($result, 1);

		//echo mysqli_error($link);

		return ["result"=>$result,"row"=>mysqli_affected_rows($link)];

	}

	public function getWhereDate(){

		$dateStar=date('Y-m-d 00：00：00');

		$dateEnd=date('Y-m-d 23：59：59');

		$wher=['FromDate'=>'2020/8/08 00:00:00','ToDate'=>'2020/8/10 23:59:59','KeyWord'=>'','ChannelID'=>'','ConsultantName'=>''];

		$data=['SqlWhere'=>json_encode($wher,JSON_UNESCAPED_UNICODE),'PageNum'=>'0',"PageSize"=>'20'];

		$a=self::posturl('http://go.qumei.com/api/CRM/CustomerDataDetail',$data);

		$count=json_decode($a,true)['Data']['TotalCount'];

		$pageNum=ceil($count/20);

		$row=0;

		for($i=0;$i<=$pageNum;$i++){

			$data=['SqlWhere'=>json_encode($wher,JSON_UNESCAPED_UNICODE),'PageNum'=>$i,"PageSize"=>'20'];
			$a=self::posturl('http://go.qumei.com/api/CRM/CustomerDataDetail',$data);

			$variable=json_decode($a,true)['Data']['Data'];

			$sqlstr=self::getFiled($variable);

			$qure="INSERT IGNORE INTO zhuanDanPhone ".$sqlstr['file']." values ".$sqlstr['val'];

			$result=self::insertDb($qure);

			if($result["result"]){

				$row+=$result["row"];
			}


		}


		return $row ;


	}

	public function getByrg(){



		$url = 'https://crm.byai.com/api/csTask/queryDoneTaskPhones';

		$parmas = ['pageNum'=>1,'pageSize'=>1,'taskId'=>150318];


		$headers[] = "Cookie:bad_ida61ef650-dcd2-11e8-a061-178bf33372a5=94dab372-bc14-11ea-b046-17a192948105; Hm_lvt_39d006e8726f3c20d0495e020413e7c4=1597970467; client-name=crm_pc; SESSION=NThiY2JjNTUtY2Q0Yy00NTA4LTk4NDAtMThlZjhiZmEyMTlj; INDATA-SESSIONID=af6fee90-6640-4d31-85a5-28ad1613e7eb; Hm_lpvt_39d006e8726f3c20d0495e020413e7c4=1597990938; Hm_lvt_32c1bc0db5aef686eecfda6ac9b996cc=1597903759,1597970478,1597982423,1597990943; crm_pc_token=crm_pc_token_8b543c640be94a4a86049184fe06839f; Hm_lpvt_32c1bc0db5aef686eecfda6ac9b996cc=1597990951; JSESSIONID=node05z99ttmlpfxz1hdkub9evocpo39463.node0; acw_tc=2f624a4f15979914073928656e4cc515a731987afce4e7743c3375305f4cd0','SESSION':'NThiY2JjNTUtY2Q0Yy00NTA4LTk4NDAtMThlZjhiZmEyMTlj; INDATA-SESSIONID=af6fee90-6640-4d31-85a5-28ad1613e7eb; Hm_lpvt_39d006e8726f3c20d0495e020413e7c4=1597990938; Hm_lvt_32c1bc0db5aef686eecfda6ac9b996cc=1597903759,1597970478,1597982423,1597990943; crm_pc_token=crm_pc_token_8b543c640be94a4a86049184fe06839f; Hm_lpvt_32c1bc0db5aef686eecfda6ac9b996cc=1597990951; JSESSIONID=node05z99ttmlpfxz1hdkub9evocpo39463.node0; acw_tc=2f624a4f15979914073928656e4cc515a731987afce4e7743c3375305f4cd0";

		$r = self::php_do_Url_GET($url,$parmas,$headers);


		var_dump($r);

	}

	public function getByrgc(){



		$url = 'https://crm.byai.com/api/customer/listFollowRecordPage';

		$parmas =['customerId'=>'2418922358','pageSize'=>'30','pageNum'=>'1'];
		


		$headers[] = "Cookie:bad_ida61ef650-dcd2-11e8-a061-178bf33372a5=94dab372-bc14-11ea-b046-17a192948105; Hm_lvt_39d006e8726f3c20d0495e020413e7c4=1597970467; client-name=crm_pc; SESSION=NThiY2JjNTUtY2Q0Yy00NTA4LTk4NDAtMThlZjhiZmEyMTlj; INDATA-SESSIONID=af6fee90-6640-4d31-85a5-28ad1613e7eb; Hm_lpvt_39d006e8726f3c20d0495e020413e7c4=1597990938; Hm_lvt_32c1bc0db5aef686eecfda6ac9b996cc=1597903759,1597970478,1597982423,1597990943; crm_pc_token=crm_pc_token_8b543c640be94a4a86049184fe06839f; Hm_lpvt_32c1bc0db5aef686eecfda6ac9b996cc=1597990951; JSESSIONID=node05z99ttmlpfxz1hdkub9evocpo39463.node0; acw_tc=2f624a4f15979914073928656e4cc515a731987afce4e7743c3375305f4cd0','SESSION':'NThiY2JjNTUtY2Q0Yy00NTA4LTk4NDAtMThlZjhiZmEyMTlj; INDATA-SESSIONID=af6fee90-6640-4d31-85a5-28ad1613e7eb; Hm_lpvt_39d006e8726f3c20d0495e020413e7c4=1597990938; Hm_lvt_32c1bc0db5aef686eecfda6ac9b996cc=1597903759,1597970478,1597982423,1597990943; crm_pc_token=crm_pc_token_8b543c640be94a4a86049184fe06839f; Hm_lpvt_32c1bc0db5aef686eecfda6ac9b996cc=1597990951; JSESSIONID=node05z99ttmlpfxz1hdkub9evocpo39463.node0; acw_tc=2f624a4f15979914073928656e4cc515a731987afce4e7743c3375305f4cd0";

		$r = self::php_do_Url_GET($url,$parmas,$headers);


		var_dump($r);

	}

}


?>